<?php

namespace app\admin\model;

use think\Model;


class ProjectStage extends Model
{


    // 表名
    protected $name = 'project_stage';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'create_time_text',
        'update_time_text',
        'project_stage_time_text',
        'progress_status_time_text',
    ];



    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
        return is_numeric($value) ? date("Y-m-d", $value) : $value;
    }


    public function getUpdateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
        return is_numeric($value) ? date("Y-m-d", $value) : $value;
    }

    public function getProjectStageTimeTextAttr($value,$data)
    {
        $value = $value ? $value : (isset($data['project_stage_time']) ? $data['project_stage_time'] : '');
        return is_numeric($value) ? date("Y-m-d", $value) : $value;
    }

    public function getProgressStatusTimeTextAttr($value,$data)
    {
        $value = $value ? $value : (isset($data['progress_status_time']) ? $data['progress_status_time'] : '');
        return is_numeric($value) ? date("Y-m-d", $value) : $value;
    }

    protected function setCreateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setUpdateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setProjectStageTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
